/*
 * @Author: 耿远风
 * @Date: 2020-04-16 20:30:20
 * @LastEditors: 耿远风
 * @LastEditTime: 2020-10-16 15:08:00
 * @Description:
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { HttpResultTransformInterceptor } from './base/interceptors/httpResult.interceptor';
import { AnyExceptionFilter } from './base/exception/any.exception';
import * as compression from 'compression';
import * as bodyParser from 'body-parser';
import { logSystemInterceptor } from './base/interceptors/logSystem.interceptor';

type NestApp = NestExpressApplication;
let app: NestApp;

export function getNestApplication(): NestApp {
  return app;
}
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    //跨域
    cors: true,
  });
  // 日志打印
  app.use(bodyParser.json({ limit: '10000kb' }));
  app.use(bodyParser.urlencoded({ extended: false, limit: '10000kb' }));
  app.use(bodyParser.text({ type: 'text/xml' }));
  app.use(logSystemInterceptor);
  app.use(compression());
  // 全局统一返回结果
  app.useGlobalInterceptors(new HttpResultTransformInterceptor());
  // 异常
  app.useGlobalFilters(new AnyExceptionFilter());
  await app.listen(3000);
}
bootstrap();
